﻿@{
    Layout = null;
}


<h2>AddManageEmployee</h2>
<link href="~/Content/css/bootstrap.min.css" rel="stylesheet" />
<script src="~/Scripts/js/jquery.min.js"></script>
<script src="~/Scripts/js/bootstrap.min.js"></script>


<div>
    <table>
        <tr>
            <th>账号：</th>
            <td><input id="Account" type="text" /></td>
        </tr>
        <tr>
            <th>密码：</th>
            <th><input id="Password" type="password" /></th>
        </tr>
        <tr>
            <th>员工名称：</th>
            <td><input id="EmployeeName" type="text" /></td>
        </tr>
        <tr>
            <th>部门：</th>
            <td><select id="Dept"></select></td>
        </tr>
        <tr>
            <th>职位：</th>
            <td><select id="Position"></select></td>
        </tr>
        <tr>
            <th colspan="2">
                <input type="button" value="注册" onclick="funRegister()" />
                &nbsp;
                <input type="button" value="返回" onclick="location.href='/Employee/ManageEmployee'" />
            </th>
        </tr>
    </table>
</div>


<script>
    $(function () {
        DeptList();
        PositionList();
    })

    //部门信息/下拉框
    function DeptList() {
        $.ajax({
            type: "post",
            url: "/Employee/RoleList",
            data: { DeptName: "" },
            success: function (obj) {
                obj = JSON.parse(obj);
                var str = "";
                for (var i = 0; i < obj.length; i++) {
                    str += "<option value='" + obj[i].DeptID + "'>" + obj[i].DeptName + "</option>"
                }
                $("#Dept").html("<option value='0'>请选择</option>" + str);
            }
        })
    }

    //职位信息/下拉框
    function PositionList() {
        $.ajax({
            type: "post",
            url: "/Employee/PositionList",
            success: function (obj) {
                obj = JSON.parse(obj);
                var str = "";
                for (var i = 0; i < obj.length; i++) {
                    str += "<option value='" + obj[i].PositionID + "'>" + obj[i].PositionName + "</option>"
                }
                $("#Position").html("<option value='0'>请选择</option>" + str);
            }
        })
    }

    //注册用户信息
    function funRegister() {
        var Account = $("#Account").val();
        var password = $("#Password").val();
        var EmployeeName = $("#EmployeeName").val();
        var DeptId = $("#Dept").val();
        var PositionId = $("#Position").val();

        if(Account!=""&&Password!=""&&EmployeeName!=""&&DeptId!=0&&PositionId!=0){
            $.ajax({
                type: "post",
                url: "/Employee/AddManageEmployeeDo",
                data: { Account: Account, Password: password, EmployName: EmployeeName, DeptID: DeptId, PositionID: PositionId },
                success:function(obj){
                    if(obj>0){
                        alert("添加成功");
                    }
                    else{
                        alert("添加失败");
                    }
                }
            })
        }
        else{
            alert("信息填写不完整")
        }
    }


</script>